<?php

namespace app\api\common;

use think\Response;

class common
{

    /**
     * 返回封装后的API数据到客户端
     * @param  mixed   $data 要返回的数据
     * @param  integer $code 返回的code
     * @param  mixed   $message 提示信息
     * @param  string  $type 返回数据格式
     * @param  array   $header 发送的Header信息
     * @return Response
     */
    public function result($data , string $message = '请求失败', int $code = 200, string $type = 'json',$header = []): Response
    {
        $result = [
            'code' => $code,
            'message'  => $message,
            'time' => time(),
            'data' => $data,
        ];
        return Response::create($result, $type)->header($header);

    }
}
